var mask = null;
var stu_id = null;
var login_user = null;
var stuData = null;
var adultMsg = null;
$(function() { // 初始化内容
	mui.init();
	stu_id

	mask = mui.createMask(); //遮罩层
	datetime_init();
	login_user = JSON.parse(localStorage.getItem('loginUser'));
	stu_id = sessionStorage.getItem('stu_id')


	setTimeout(function() {
		loadClient(stu_id)
		getSaler();
	}, 300);


})

function tap_init() {

	jQuery(document).ready(function() {

		jQuery("#salerval").change(function() {

			var salerval = $('#salerval option:selected').val();




		});

	});



}

function audit() {
	document.querySelector("#modal").classList.add("mui-active");
}

function loadClient(stu_id) {
	var data = {};
	data['id'] = stu_id
	jQuery.ajax({
		headers: {
			'Authorization': login_user.token
		},
		type: "post",
		url: serverip + "fxgw/loadkh",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {

			mask.show(); //显示遮罩层
		},
		success: function(res) {

			mask.close(); //显示遮罩层
			console.log("优惠记录======" + JSON.stringify(res));
			loadForm(res.stulist[0]);
			stuData = res.stulist[0]



		},

		error: function(e) {

			mask.close(); //显示遮罩层
			mui.alert('系统错误');
			console.log(JSON.stringify(e));
		}
	});
}


function getSaler() {
	var data = {};
	data['positions'] = "分校顾问"
	data['schoolid'] = login_user.schoolid
	jQuery.ajax({
		headers: {
			'Authorization': login_user.token
		},
		type: "post",
		url: serverip + "newxlc_personnel/getsaler",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {

			mask.show(); //显示遮罩层
		},
		success: function(res) {

			mask.close(); //显示遮罩层
			console.log("顾问======" + JSON.stringify(res));

			jQuery("#salerval").find("option").remove();

			var str = "<option value=\"\">请选择</option>";
			for (var j = 0; j < res.length; j++) {
				str += "<option value=\"" + res[j].id + "\" >" + res[j].name + "</option>";
			}

			jQuery("#salerval").append(str);



		},

		error: function(e) {

			mask.close(); //显示遮罩层
			mui.alert('系统错误');
			console.log(JSON.stringify(e));
		}
	});
}


function save() {
	var data = {};
	data['actionType'] = "POST"
	data['ids'] = stu_id
	
	data['savePath'] = "/fxxz/sqAdult"
	data['auditstatus'] = adultMsg
	console.log(JSON.stringify(data))
	jQuery.ajax({
		headers: {
			'Authorization': login_user.token
		},
		type: "post",
		url: serverip + "fxxz/fp",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {

			mask.show(); //显示遮罩层
		},
		success: function(res) {

			mask.close(); //显示遮罩层
			mui.alert('分配完成');

			setTimeout(function() {
				mui.back();
			}, 1000);



		},

		error: function(e) {

			mask.close(); //显示遮罩层
			mui.alert('系统错误');
			console.log(JSON.stringify(e));
		}
	});
}


function pass(){
	adultMsg = "校长审核通过"
	save();
}

function noPass(){
	
	adultMsg = "校长审核不通过"
	save();
}